//
//  ViewController.m
//  苏州银行
//
//  Created by rimi on 15/8/18.
//  Copyright (c) 2015年 IOS. All rights reserved.
//

#import "BasicViewController.h"
#import "LeftButtonTableViewCell.h"
#import "SZYHViewController.h"//父类
#import "SZYHFinacialInformationViewController.h"//金融业务
#import "SZYHBusinessViewController.h"//银行业务
#import "SZYHInvestingAndFinancingViewController.h"//投资理财
#import "SZYHCityzonCardViewController.h"//市民卡
#import "SZYHPublicGoodsViewController.h"//对公产品
#import "SZYHMapViewController.h"//网点地图
#import "SZYHMyBankViewController.h"//我的银行
#import "SZYHMyEmailViewController.h"//我的邮箱类
#import "SZYHChangePasswordViewController.h"//修改密码
#import "SZYHSettingViewController.h"//设置框
#import "InvestmentViewController.h"
#import "AppDelegate.h"


@interface BasicViewController ()<UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate,UIAlertViewDelegate>
@property (nonatomic, strong) NSArray           *imageName;
@property (nonatomic, strong) UIViewController  *iteration;
@property (nonatomic, strong) UIViewController  *changePasswordController;
@property (nonatomic, copy) NSArray             *viewControllers;
- (IBAction)changeHeaderImage:(id)sender;
- (IBAction)exitAppButton:(id)sender;

@end

@implementation BasicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self initializeDataSource];
    [self initializeUserInterface];

//    NSLog(@"%@",NSHomeDirectory());
}
-(void)initializeDataSource
{
    _imageName = @[@"金融资讯.png",@"银行业务.png",@"投资理财.png",@"市民卡.png",@"对公产品.png",@"网点地图.png",@"我的银行.png"];
    SZYHFinacialInformationViewController *finacialInfo = [[SZYHFinacialInformationViewController alloc]init];
    SZYHBusinessViewController *business = [[SZYHBusinessViewController alloc]init];
    UIStoryboard *investVC= [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    SZYHInvestingAndFinancingViewController *SZYHInvest = [investVC instantiateViewControllerWithIdentifier:@"INVEST"];
   
    SZYHCityzonCardViewController *cityCard = [[SZYHCityzonCardViewController alloc]init];
    SZYHPublicGoodsViewController *publicGoods = [[SZYHPublicGoodsViewController alloc]init];
    SZYHMapViewController *mapVC = [[SZYHMapViewController alloc]init];
    SZYHMyBankViewController *myBank = [[SZYHMyBankViewController alloc]init];
    _viewControllers = @[finacialInfo,business,SZYHInvest,cityCard,publicGoods,mapVC,myBank];

}
-(void)initializeUserInterface
{
    self.leftTableView.delegate = self;
    self.leftTableView.dataSource = self;
    self.leftTableView.rowHeight = 98;
    self.leftTableView.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
    
    

    //底部消息按钮
    [_topInfoButton addTarget:self action:@selector(topInfoButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
    return  _imageName.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LeftButtonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LEFTCELL"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
    cell.imageView.image = [UIImage imageNamed:_imageName[indexPath.row]];
    return cell;

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [_iteration removeFromParentViewController];
    [_iteration.view removeFromSuperview];
    if (indexPath.row == 2) {
        UIStoryboard *investVC= [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
        SZYHInvestingAndFinancingViewController *SZYHInvest = [investVC instantiateViewControllerWithIdentifier:@"INVEST"];
        [self addChildViewController:SZYHInvest];
        [self.view addSubview:SZYHInvest.view];
        _iteration = SZYHInvest;
    }else {
        SZYHViewController *viewController =_viewControllers[indexPath.row];
        [self addChildViewController:viewController];
        [self.view addSubview:viewController.view];
        _iteration = viewController;
        
        
    }
   

    
    
}
//弹出修改密码窗口
- (IBAction)changePasswordButtonPressed:(id)sender {

    UIStoryboard *changeSotory = [UIStoryboard storyboardWithName:@"XWChangePassword" bundle:nil];
    SZYHChangePasswordViewController *SZYHChangeVC = [[SZYHChangePasswordViewController alloc]init];
    SZYHChangeVC = [changeSotory instantiateViewControllerWithIdentifier:@"CHANGE"];
    [self.view addSubview:SZYHChangeVC.view];
    [self addChildViewController:SZYHChangeVC];
    
}
//弹出设置框
- (IBAction)settingButtonPressed:(id)sender {
    UIStoryboard *changeSotory = [UIStoryboard storyboardWithName:@"Setting" bundle:nil];
    SZYHSettingViewController *SZYHSettingVC = [[SZYHSettingViewController alloc]init];
    SZYHSettingVC = [changeSotory instantiateViewControllerWithIdentifier:@"SETTING"];
    [self.view addSubview:SZYHSettingVC.view];
    [self addChildViewController:SZYHSettingVC];
}

//底部消息按钮响应
- (void)topInfoButtonEvent:(UIButton *)sender{
    SZYHMyEmailViewController *meVC = [[SZYHMyEmailViewController alloc]init];
    [self.view addSubview:meVC.view];
    [self addChildViewController:meVC];
}
    

- (IBAction)changeHeaderImage:(id)sender {
    //弹出选项框
    UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"上传头像" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"系统相册",@"拍照 ", nil];
    action.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [action showInView:self.view];
}

- (IBAction)exitAppButton:(id)sender {
    //弹出提示框
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"您确定要退出吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert show];
}

#pragma mark - <UIAlertViewDelegate>
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) {
        [self exitApplication];
    }
}

//退出程序
- (void)exitApplication {
    
    AppDelegate *app = [UIApplication sharedApplication].delegate;
    UIWindow *window = app.window;
    
    [UIView animateWithDuration:0.1f animations:^{
        window.alpha = 0;
        window.frame = CGRectMake(0, 0, 0, 0);
    } completion:^(BOOL finished) {
        exit(0);
    }];
}
@end
